package com.ruoyi.common.core.page;

import com.ruoyi.common.constant.HttpStatus;

import java.util.List;
import java.util.stream.Collectors;

//手动分页
public class ManualPagination {
    public static TableDataInfo pagination(List<?> list) {
        // 数据手动分页
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setRows(
                list.stream().skip((long) (pageNum - 1) * pageSize)
                        .limit(pageSize)
                        .collect(Collectors.toList()));
        rspData.setTotal(list.size());
        return rspData;
    }
}
